// pages/brand/info.js
var imageUtil = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    httphost: app.data.httphost,
    httpserver: app.data.httpserver,
  },
  bannerLoad: function (e) {
    var that = this; 
    var imageSize = that.imageUtilWidth(e);
    this.setData({
      bannerwidth: imageSize.imageWidth,
      bannerheight: imageSize.imageHeight
    })
  }, 
  imageUtilWidth:function (e) {
    var imageSize = {};
    var originalWidth = e.detail.width;//图片原始宽  
    var originalHeight = e.detail.height;//图片原始高  
    var originalScale = originalHeight / originalWidth;//图片高宽比  
    //获取屏幕宽高  
    wx.getSystemInfo({
      success: function (res) {
        var windowWidth = res.windowWidth;
        var windowHeight = res.windowHeight;
        var windowscale = windowHeight / windowWidth;//屏幕高宽比  
        //图片缩放后的宽为屏幕宽  
        imageSize.imageWidth = windowWidth;
        imageSize.imageHeight = (windowWidth * originalHeight) / originalWidth;
      }
    })
    return imageSize;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.onLaunch();
    var that = this; 
    wx.request({
      url: app.data.httpserver + 'userScore/list?bannerType=5',
      header: wx.getStorageSync('header'),
      success:function(resqust){
        var banner = resqust.data.bannerlist

        //组合轮播图片
        for (var i = 0; i < banner.length;i++){
          var app_url = banner[i].app_url

          var attr_value = '';
          if (typeof (app_url) != 'undefined' && app_url.indexOf('/')!=-1){
              banner[i].app_url = app_url.split('/')[0];
              // var attr_name_value = app_url.split('?')[1].split('=');
              var attr_value = app_url.split('/')[1];
          }
          banner[i].attr_value = attr_value;
        }
        that.setData({
          banner: banner,
          cart_count: resqust.data.cart_count,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})